﻿eventModule.factory("EventService", function ($http, $q) {
    return {
        addVacancy: function (vacancy) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'POST', url: '/Vacancy/Create', data: vacancy }).success(deferred.resolve).error(deferred.reject);
            //$http.post('/events/AddTalk', talk).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        deleteVacant: function (vacancy_id) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'GET', url: '/Vacancy/Delete/' + vacancy_id }).success(deferred.resolve).error(deferred.reject);
            //$http.post('/events/AddTalk', talk).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        copyVacant: function (vacancy_id) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'GET', url: '/Vacancy/Copy/' + vacancy_id }).success(deferred.resolve).error(deferred.reject);
            //$http.post('/events/AddTalk', talk).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        getVacancys: function () {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'GET', url: '/Vacancy/List' }).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        getVacancy: function (vacancy_id) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'GET', url: '/Vacancy/Get/' + vacancy_id }).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        updateVacancy: function (vacancy) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'POST', url: '/Vacancy/Update', data: vacancy }).success(deferred.resolve).error(deferred.reject);
            //$http.post('/events/AddTalk', talk).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        getSkills: function (vacancy_id) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'GET', url: '/Skill/List/' + vacancy_id }).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        addSkill: function (skill) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'POST', url: '/Skill/Create', data: skill }).success(deferred.resolve).error(deferred.reject);
            //$http.post('/events/AddTalk', talk).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        deleteSkill: function (vacancy_id, skill_id) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'GET', url: '/Skill/Delete/' + vacancy_id + '/' + skill_id }).success(deferred.resolve).error(deferred.reject);
            //$http.post('/events/AddTalk', talk).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        getApplicants: function (vacancy_id) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'GET', url: '/Applicant/List/' + vacancy_id }).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        rankApplicants: function (cert) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'POST', url: '/Rank/Do', data: cert }).success(deferred.resolve).error(deferred.reject);
            //$http.post('/events/AddTalk', talk).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        },
        compareApplicants: function (app) {
            // Get the deferred object
            var deferred = $q.defer();
            // Initiates the AJAX call
            $http({ method: 'POST', url: '/Compare/Do', data: app }).success(deferred.resolve).error(deferred.reject);
            //$http.post('/events/AddTalk', talk).success(deferred.resolve).error(deferred.reject);
            // Returns the promise - Contains result once request completes
            return deferred.promise;
        }
    }
});